import { Column, CreateDateColumn, Entity, JoinTable, ManyToMany, PrimaryGeneratedColumn, UpdateDateColumn } from "typeorm";
import { Permission } from "@/modules/permission/entities/permission.entity";
import { User } from "@/modules/user/entities/user.entity";

@Entity()
export class Role {

  @PrimaryGeneratedColumn()
  id: number;

  @Column({ unique: true, length: 50 })
  roleCode: string;

  @Column({ unique: true, length: 50 })
  roleName: string;

  @Column({ default: true })
  status: boolean;

  @ManyToMany(() => User, (User) => User.roles, {
    createForeignKeyConstraints: false,
  })
  users: User[];

  @ManyToMany(() => Permission, (Permission) => Permission.roles, {
    createForeignKeyConstraints: false,
  })
  @JoinTable()
  permissions: Permission[];

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;
}
